#region Usings
using System.Web;
using BK.BL;
using BK.Entities;
using Lib.ApplicationBlocks.DbBlocks.Membership;
using Lib.Data.CriteriaRoutine;
#endregion

namespace BK.WebSite.AppCode
{
    public class UserProvider : GeneralMembershipProvider
    {
    	private static UserProvider _instance;
    	private static object _lockObj = new object();
    	private static object _lockObj2 = new object();

        #region Instance Methods
        protected override IMembership CreateInstanceOfMembership(string login, string password)
        {
            return new UserEntity {Login = login, Password = password};
        }
        #endregion

        #region Instance Properties
        protected override IMgrMemberships MgrMemberships
        {
            get { return BlContext.Instance.Users; }
        }
        #endregion

        #region Class Methods
        public static UserEntity GetCurrentUser()
        {
            return BlContext.Instance.Users.LoadSingle(new Criteria("Login", Clause.Eq,
                                                                    HttpContext.Current.User.Identity.Name));
        }
        #endregion

    	public static UserProvider Instance
    	{
    		get
    		{
    			lock (_lockObj)
    			{
					if (_instance == null)
					{
						lock (_lockObj2)
						{
							_instance = new UserProvider();
						}
					}
    			}
				return _instance;
    		}
    	}
    }
}